package reflect;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 使用反射机制完成如下功能:
 * File file=new File("./test.txt");
 */
public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class cls=Class.forName("java.io.File");
        Constructor con=cls.getConstructor(String.class);
        Object obj=con.newInstance("./test.txt");
        System.out.println(obj);
    }

}
